package com.wulijie.intermediary;

import java.util.HashMap;

/**
 * @Author cui
 * @Data
 */
public class SpecificMediary extends Mediary{
    private HashMap<String, Colleague> map1;
    private HashMap<String, Colleague> map2;

    public SpecificMediary() {
        map1 = new HashMap<>();
        map2 = new HashMap<>();
    }

    @Override
    void getMessage(String name, int state) {
        if (this.map1.get(name) instanceof TV1) {
            if (state == 0) {
                TV1 colleague = (TV1)this.map2.get("tv1");
                colleague.m1();
                TV2 colleague2 = (TV2)this.map2.get("tv2");
                colleague2.m1();
                colleague2.m2();
            }
            if (state == 1) {
                TV1 colleague = (TV1)this.map2.get(name);
                colleague.m1();
            }
        } if (this.map1.get(name) instanceof TV2) {
            //...
        }
    }

    @Override
    void register(String name, Colleague colleague) {
        map1.put(name, colleague);

        if (colleague instanceof TV1) {
            map2.put("tv1", colleague);
        } if (colleague instanceof TV2) {
            map2.put("tv2", colleague);
        }
    }
}
